package com.zt.rongda.salary.controller;

import com.zt.servlet.*;
import com.zt.rongda.salary.model.SalaryPayRollQuota;
import com.zt.rongda.salary.service.SalaryPayRollQuotaService;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

@Controller
@RequestMapping(value = "/salaryPayRollQuota")
public class SalaryPayRollQuotaController {

    @Autowired
    private SalaryPayRollQuotaService salaryPayRollQuotaService;

    @RequestMapping(value = "/query")
    @ResponseBody
    
    public JSONObject query(@RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
        return Response.response(salaryPayRollQuotaService.getTable(reqBean));
    }

    @RequestMapping(value = "/add")
    @ResponseBody
    
    public JSONObject add(@RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
        salaryPayRollQuotaService.add(getSalaryPayRollQuota(reqBean));
        return Response.responseSuccess();
    }

    @RequestMapping(value = "/update")
    @ResponseBody
    
    public JSONObject update(@RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
        salaryPayRollQuotaService.update(getSalaryPayRollQuota(reqBean));
        return Response.responseSuccess();
    }

    @RequestMapping(value = "/delete")
    @ResponseBody
    
    public JSONObject delete(@RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
        salaryPayRollQuotaService.delete(reqBean.getInfo("id"));
        return Response.responseSuccess();
    }

    /**
    * 从表单获取对象
    *
    * @param reqBean
    * @return
    */
    private SalaryPayRollQuota getSalaryPayRollQuota(ReqBean reqBean) {
        SalaryPayRollQuota salaryPayRollQuota = new SalaryPayRollQuota();
        salaryPayRollQuota.setId(reqBean.getInfo("id"));
        salaryPayRollQuota.setPayrollId(reqBean.getInfo("payrollId"));
        salaryPayRollQuota.setTaskId(reqBean.getInfo("taskId"));
        salaryPayRollQuota.setWorkStepId(reqBean.getInfo("workStepId"));
        salaryPayRollQuota.setTaskQuota(reqBean.getInfoDouble("taskQuota"));
        salaryPayRollQuota.setEmpId(reqBean.getInfo("empId"));
        salaryPayRollQuota.setEmpQuota(reqBean.getInfoDouble("empQuota"));
        salaryPayRollQuota.setQuotaSalary(reqBean.getInfoDouble("quotaSalary"));
        salaryPayRollQuota.setOperator(reqBean.getUserId());
        salaryPayRollQuota.setRemark(reqBean.getInfo("remark"));
        return salaryPayRollQuota;
    }

}